<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="mini" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="订单编号" prop="orderNo">
        <el-input v-model="queryParams.orderNo" placeholder="请输入订单编号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="会员编号" prop="custNo">
        <el-input v-model="queryParams.custNo" placeholder="请输入会员编号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!-- <el-form-item label="会员昵称" prop="custName">
        <el-input v-model="queryParams.custName" placeholder="请输入会员昵称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item label="产品名称" prop="productName">
        <el-input v-model="queryParams.productName" placeholder="请输入产品名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item> -->

      <el-form-item label="物流单号" prop="billNo">
        <el-input v-model="queryParams.billNo" placeholder="请输入物流单号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item label="订单状态"
        prop="status">
        <el-select v-model="queryParams.status"
          clearable
          placeholder="请选择订单状态"
          @keyup.enter.native="handleQuery"
          >
          <el-option v-for="dict in dict.type.order_status"
            :key="dict.value"
            :label="dict.label"
            :value="parseInt(dict.value)" />
        </el-select>
      </el-form-item>

      <el-form-item label="物流状态"
        prop="procStatus">
        <el-select v-model="queryParams.procStatus"
          clearable
          placeholder="请选择物流状态"
          @keyup.enter.native="handleQuery"
          >
          <el-option v-for="dict in dict.type.proc_status"
            :key="dict.value"
            :label="dict.label"
            :value="parseInt(dict.value)" />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['web:items:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['web:items:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['web:items:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['web:items:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="itemsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="编号" align="center" prop="id" /> -->
      <!-- <el-table-column label="订单ID" align="center" prop="orderId" /> -->
      <el-table-column label="订单编号" align="center" prop="orderNo" width="150" />
      <!-- <el-table-column label="会员ID" align="center" prop="custId" /> -->
      <el-table-column label="会员编号" align="center" prop="custNo" />
      <el-table-column label="会员昵称" align="center" prop="custName" />
      <!-- <el-table-column label="产品ID" align="center" prop="productId" /> -->
      <el-table-column label="产品编号" align="center" prop="productNo" />
      <el-table-column label="产品名称" align="center" prop="productName" />
      <!-- <el-table-column label="skuId" align="center" prop="skuId" />
      <el-table-column label="sku名称" align="center" prop="skuName" /> -->
      <el-table-column label="商品缩图" align="center" prop="productImg">
        <template slot-scope="scope">
          <div>
            <el-image style="width: 50px; height: 50px; border-radius: 4px" :src="scope.row.productImg" fit="cover"
              preview-teleported="true" />
          </div>
        </template>
      </el-table-column>
      <el-table-column label="原价" align="center" prop="price" />
      <el-table-column label="成交价" align="center" prop="salPrice" />
      <el-table-column label="数量" align="center" prop="qty" />
      <el-table-column label="单位" align="center" prop="unit" />
      <!-- 总重量 =  销售数量 * 商品单位重量 -->
      <el-table-column label="总重量" align="center" prop="weight" />
      <!--  销售金额 = 原价*数量 -->
      <el-table-column label="销售金额" align="center" prop="saleMoney" />
      <!-- 实际金额 = 实际成交价 * 销售数量 -->
      <el-table-column label="实际金额" align="center" prop="dealMoney" />
      <el-table-column label="优惠金额" align="center" prop="discount" />
      <!--  0 未生效 1 已生效 2 客户取消 3 后台取消 -->
      <el-table-column label="订单状态"
        align="center"
        prop="status"
        min-width="100">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.order_status"
            :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column label="库存单位" align="center" prop="stockUnit" />
      <el-table-column label="库存数量" align="center" prop="stockQty" />
      <!-- 【1 已出库 2 配送中 3 已签收 4 已退货】 -->
      <el-table-column label="物流状态"
        align="center"
        prop="procStatus"
        min-width="160"
        show-overflow-tooltip >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.proc_status"
            :value="scope.row.procStatus" />
        </template>
      </el-table-column>
      <el-table-column label="物流单号" align="center" prop="billNo" width="140"/>
      <!-- <el-table-column label="物流公司代码" align="center" prop="expCode" /> -->
      <el-table-column label="公司名称" align="center" prop="expName" />
      <el-table-column label="发货时间" align="center" prop="billDt" width="140"/>
      <!-- 【0 未评价 1 已评价】 -->
      <!-- <el-table-column label="评价状态" align="center" prop="commentStatus" /> -->
      <el-table-column label="单位重量" align="center" prop="unitWeight" />
      <el-table-column label="创建时间" align="center" prop="createDt" width="140"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" min-width="180" fixed="right">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['web:items:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['web:items:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改商城详查明细对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="订单ID" prop="orderId">
          <el-input v-model="form.orderId" placeholder="请输入订单ID" />
        </el-form-item>
        <el-form-item label="订单编号" prop="orderNo">
          <el-input v-model="form.orderNo" placeholder="请输入订单编号" />
        </el-form-item>
       
        <el-form-item label="会员ID" prop="custId">
          <el-input v-model="form.custId" placeholder="请输入会员ID" />
        </el-form-item>
        <el-form-item label="会员编号" prop="custNo">
          <el-input v-model="form.custNo" placeholder="请输入会员编号" />
        </el-form-item>
        <el-form-item label="会员昵称" prop="custName">
          <el-input v-model="form.custName" placeholder="请输入会员昵称" />
        </el-form-item>
        <el-form-item label="产品ID" prop="productId">
          <el-input v-model="form.productId" placeholder="请输入产品ID" />
        </el-form-item>
        <el-form-item label="产品编号" prop="productNo">
          <el-input v-model="form.productNo" placeholder="请输入产品编号" />
        </el-form-item>
        <el-form-item label="产品名称" prop="productName">
          <el-input v-model="form.productName" placeholder="请输入产品名称" />
        </el-form-item>
        <el-form-item label="skuId" prop="skuId">
          <el-input v-model="form.skuId" placeholder="请输入skuId" />
        </el-form-item>
        <el-form-item label="sku名称" prop="skuName">
          <el-input v-model="form.skuName" placeholder="请输入sku名称" />
        </el-form-item>
        <!-- <el-form-item label="商品缩图" prop="productImg">
          <el-input v-model="form.productImg" placeholder="请输入商品缩图" />
        </el-form-item> -->
        <el-table-column label="商品缩图" align="center" prop="productImg">
          <template slot-scope="scope">
            <div>
              <el-image style="width: 50px; height: 50px; border-radius: 4px" :src="scope.row.productImg"
                :preview-src-list="[scope.row.productImg]" fit="cover" preview-teleported="true" />
            </div>
          </template>
        </el-table-column>
        <el-form-item label="条码" prop="barcode">
          <el-input v-model="form.barcode" placeholder="请输入条码" />
        </el-form-item>
        <el-form-item label="原价" prop="price">
          <el-input v-model="form.price" placeholder="请输入原价" />
        </el-form-item>
        <el-form-item label="成交价" prop="salPrice">
          <el-input v-model="form.salPrice" placeholder="请输入成交价" />
        </el-form-item>
        <el-form-item label="数量" prop="qty">
          <el-input v-model="form.qty" placeholder="请输入数量" />
        </el-form-item>
        <el-form-item label="单位" prop="unit">
          <el-input v-model="form.unit" placeholder="请输入单位" />
        </el-form-item>
        <el-form-item label="总重量 =  销售数量 * 商品单位重量" prop="weight">
          <el-input v-model="form.weight" placeholder="请输入总重量 =  销售数量 * 商品单位重量" />
        </el-form-item>
        <el-form-item label="销售金额 = 原价*数量" prop="saleMoney">
          <el-input v-model="form.saleMoney" placeholder="请输入销售金额 = 原价*数量" />
        </el-form-item>
        <el-form-item label="实际金额 = 实际成交价 * 销售数量" prop="dealMoney">
          <el-input v-model="form.dealMoney" placeholder="请输入实际金额 = 实际成交价 * 销售数量" />
        </el-form-item>
        <el-form-item label="优惠金额【使用优惠券】" prop="discount">
          <el-input v-model="form.discount" placeholder="请输入优惠金额【使用优惠券】" />
        </el-form-item>
        <el-form-item label="disp_bill.id" prop="billId">
          <el-input v-model="form.billId" placeholder="请输入disp_bill.id" />
        </el-form-item>
        <el-form-item label="1：待评价 2：已评价" prop="commentFlag">
          <el-input v-model="form.commentFlag" placeholder="请输入1：待评价 2：已评价" />
        </el-form-item>
        <el-form-item label="库存单位" prop="stockUnit">
          <el-input v-model="form.stockUnit" placeholder="请输入库存单位" />
        </el-form-item>
        <el-form-item label="库存数量比率" prop="qtyRate">
          <el-input v-model="form.qtyRate" placeholder="请输入库存数量比率" />
        </el-form-item>
        <el-form-item label="库存数量 qty * qty_rate" prop="stockQty">
          <el-input v-model="form.stockQty" placeholder="请输入库存数量 qty * qty_rate" />
        </el-form-item>
        <el-form-item label="创建人员" prop="createDt">
          <el-input v-model="form.createDt" placeholder="请输入创建人员" />
        </el-form-item>
        <el-form-item label="商品是否解冻上级库存 0 不解冻 1解冻" prop="thawTag">
          <el-input v-model="form.thawTag" placeholder="请输入商品是否解冻上级库存 0 不解冻 1解冻" />
        </el-form-item>

        <el-form-item label="单位重量" prop="unitWeight">
          <el-input v-model="form.unitWeight" placeholder="请输入单位重量" />
        </el-form-item>
        <el-form-item label="物流单号" prop="billNo">
          <el-input v-model="form.billNo" placeholder="请输入物流单号" />
        </el-form-item>
        <el-form-item label="物流公司代码" prop="expCode">
          <el-input v-model="form.expCode" placeholder="请输入物流公司代码" />
        </el-form-item>
        <el-form-item label="物流公司名称" prop="expName">
          <el-input v-model="form.expName" placeholder="请输入物流公司名称" />
        </el-form-item>
        <el-form-item label="发货时间" prop="billDt">
          <el-input v-model="form.billDt" placeholder="请输入发货时间" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listItems, getItems, delItems, addItems, updateItems } from "@/api/djk/orderMgr/expressOrder";

export default {
  name: "Items",
  dicts: ["order_type", "order_status", "pay_type", "pay_status", "yes_no", "proc_status"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 商城详查明细表格数据
      itemsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        // orderType: 4,
        orderId: null,
        orderNo: null,
        custId: null,
        custNo: null,
        custName: null,
        productId: null,
        productNo: null,
        productName: null,
        skuId: null,
        skuName: null,
        productImg: null,
        barcode: null,
        price: null,
        salPrice: null,
        qty: null,
        unit: null,
        weight: null,
        saleMoney: null,
        dealMoney: null,
        discount: null,
        billId: null,
        commentFlag: null,
        status: 1,
        stockUnit: null,
        qtyRate: null,
        stockQty: null,
        createDt: null,
        thawTag: null,
        sysAccount: null,
        procStatus: null,
        commentStatus: null,
        unitWeight: null,
        billNo: null,
        expCode: null,
        expName: null,
        billDt: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询商城详查明细列表 */
    getList() {
      this.loading = true;
      listItems(this.queryParams).then(response => {
        this.itemsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        orderId: null,
        orderNo: null,
        custId: null,
        custNo: null,
        custName: null,
        productId: null,
        productNo: null,
        productName: null,
        skuId: null,
        skuName: null,
        productImg: null,
        barcode: null,
        price: null,
        salPrice: null,
        qty: null,
        unit: null,
        weight: null,
        saleMoney: null,
        dealMoney: null,
        discount: null,
        billId: null,
        commentFlag: null,
        status: 1,
        stockUnit: null,
        qtyRate: null,
        stockQty: null,
        createDt: null,
        createBy: null,
        thawTag: null,
        sysAccount: null,
        procStatus: null,
        commentStatus: null,
        unitWeight: null,
        billNo: null,
        expCode: null,
        expName: null,
        billDt: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加商城详查明细";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getItems(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改商城详查明细";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateItems(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addItems(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除商城详查明细编号为"' + ids + '"的数据项？').then(function () {
        return delItems(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('web/items/export', {
        ...this.queryParams
      }, `items_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
